package com.neusoft.freshmenapp.util;

import org.json.JSONObject;

import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

public class Httputil {

    public static void request(String uri , JSONObject param , Callback callback){
        //创建OkHttpClient实例
        OkHttpClient client = new OkHttpClient();

        //设置请求参数是json格式
        MediaType jsonType = MediaType.parse("application/json; charset=utf-8");
        //参数内容
        RequestBody requestBody = RequestBody.create(jsonType, String.valueOf(param));

        //创建请求
        Request request = new Request.Builder()
                .url(uri)
                .post(requestBody)
                .build();
        //发送请求
        client.newCall(request).enqueue(callback);
    }
}
